using Godot;
using System;

public partial class SkillPunch : SkillBase
{
	private Punch punch;
	public override void _Ready()
	{
		this.name = "拳击";
		this.type = TYPE.SUMMON;
		
	}

	public override void _Process(double delta)
	{
	}

    public override void SkillTocharacter(Characters owner, Characters _character)
    {
		if(owner.HasNode("Punch"))
		{return;}
        base.SkillTocharacter(owner, _character);
		string path = "res://resources/summon_object/punch.tscn";
		var Game = GetNode<Game>("/root/Game");
		punch = Game.InstantScene(path) as Punch;

		punch.SetAttack(owner.CharacterData.attack);
		var dir = (90 - owner.MoveDirection()) / 180 * Math.PI;
		punch.Position = new Vector2((float)Math.Cos(dir) * 10,(float)Math.Sin(dir) * 10)*3;
		punch.Rotation = (float)dir;
		if(owner is Player)
		{
			Player player = (Player)owner;
			var _mouseposition= player.GetGlobalMousePosition();
			var direction = player.MouseDirection(_mouseposition);
			dir = (90-direction) / 180 * Math.PI;
			punch.Scale = new Vector2(1,1);
			punch.Position = new Vector2((float)Math.Cos(dir) * 10,(float)Math.Sin(dir) * 10);
			punch.Rotation = (float)dir;

		}

		owner.AddChild(punch);
		punch.GetNode<AnimationPlayer>("AnimationPlayer").Play("punch");
		punch.GetNode<AnimationPlayer>("AnimationPlayer").AnimationFinished += Finished;
    }

	public void Finished(StringName a)
	{
		//GD.Print("动画结束信号");
		punch.QueueFree();
		//GD.Print("释放节点");
	}
}
